package cn.vortex.device.dao.impl;

import cn.vortex.device.vo.DownItem;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DownItemDaoImpl extends AbstractBaseDaoImpl<DownItem> {

    public int add(DownItem downItem) throws SQLException {
        //String sql = "insert into t_downItem(name,number,category,price,QGP,specs,factory," +
        //        "buyDate,downDate,opinion,doPerson)values(?,?,?,?,?,?,?,?,?,?,?)";

        //return queryRunner.update(sql,downItem.getName(),downItem.getNumber(),downItem.getCategory(),
        //        downItem.getPrice(),downItem.getQGP(),downItem.getSpecs(),downItem.getFactory(),
        //        downItem.getBuyDate(),downItem.getDownDate(),downItem.getOpinion(),downItem.getDoPerson());

        //Oracle
        String sql = "insert into t_downItem(\"number\",downDate,downReason,downPerson) " +
                "values(?,to_Date(?, 'YYYY-MM-DD HH24:MI:SS'),?,?)";

        Date downDate = downItem.getDownDate();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String downDateStr = sdf.format(downDate);

        return queryRunner.update(sql,downItem.getNumber(),downDateStr,
                downItem.getOpinion(),downItem.getDoPerson());
    }

}
